<template>
    <div class="shouhou">
        <div class="header-top">
            <div @click="leftBtn" class="arrow-left">
                <img src="../../images/jiantou.png" alt="">
            </div>
        </div>
        <div class="shouhou-bd">
            <div class="shouhou-card" >
                <div v-if="!type" v-for="(item,index) in detail.orderItems" :key="index">                
                    <card :imgSrc="item.modelImageUrl" :name="item.productTitle">
                        <div class="good-desc">
                            <span class="good-desc-info">{{item.modelName}}  {{item.modelSize}}</span>
                        </div>
                        <div class="good-price">
                            <span class="price-icon">￥</span>
                            <span class="good-price-num">{{item.totalPrice}}</span>
                        </div>
                        <div class="good-count">
                            x{{item.count}}
                        </div>
                    </card>
                </div>
                <div v-if="type" >                
                    <card :imgSrc="detail.productImageUrl" :name="detail.productTitle">
                        <div class="good-desc">
                            <span class="good-desc-info">{{detail.modelName}}  {{detail.modelSize}}</span>
                        </div>
                        <div class="good-price">
                            <span class="price-icon">￥</span>
                            <span class="good-price-num">{{detail.price}}</span>
                        </div>
                        <div class="good-count">
                            x{{detail.count}}
                        </div>
                    </card>
                </div>
            </div>
            <div v-if="!id" class="shouhou-select" >
                <div class="shouhou-item" v-for="(item,index) in selectlist" :key="index"
                :class="{'shouhou-item-on':curIndex==index
                    }" @click="changeselect(index)">{{item.label}}</div>
            </div>
            <div v-if="id" class="shouhou-select" >
                {{refundD.refundType == 'ONLYREFUND'?'退款':'退货'}}
            </div>
            <div class="backmoney-amount" v-if="curIndex == 0">
                物流公司
            </div>
            <div class="input-amount" v-if="curIndex == 0">
                <select v-model="params.logisticsCompany">
                    <option v-for="(item,index) in selectArr" :value="item.value" :key="index">{{item.value}}</option>
                </select>
            </div>
           <div class="backmoney-amount" v-if="curIndex == 0">
                物流单号
            </div>
            <div class="input-amount" v-if="curIndex == 0">
                <input type="text" v-model="params.shipmentNumber">
            </div>
             <div class="backmoney-amount">
                申请退款原因
            </div>
            <div class="input-amount2">
                <div class="reason-text" v-if="id">{{refundD.reason}}</div>
                <textarea v-else type="text" v-model="params.reason" placeholder="请输入退款原因"/>
            </div>
            <div v-if="!id" class="uploadimg">
                <div class="uploadimg-hint">请上传图片</div>
                <div class="uploadimg-click flex-box-align" >

                    <!--<div class="uploaded-img" v-show="curIndex==0||curIndex==1">-->
                        <!--<img src="../../images/shangchuantupian2@2x.png" alt="" >-->
                        <!--<img src="../../images/remove@2x.png" alt="" class="img-remove"-->
                        <!--&gt;-->
                    <!--</div>-->
                    <ul class="flex-box-container">
                        <li v-for="(item, index) in params.imageList" :key="index">
                            <img :src="item.fileUrl" alt=""/>
                            <img src="../../images/remove@2x.png" alt="" class="img-remove" @click="handleDel(index)"/>
                        </li>
                        <div v-if="params.imageList.length<5" class="upload-input">
                            <input class="hidden-input" type="file" name="image" accept="image/*" @change="handleSelectPic">
                            <img src="../../images/shangchuantupian@2x.png" alt="">
                        </div>
                    </ul>
                     
                </div>
                <div class="uploadimg-limit">上传图片大小不超过5M，最多5张</div>
            </div>
            <div v-if="id" class="img-wrap">
                <div class="name">申请退款图片</div>
                <div v-for="(item,index) in refundD.imageList" :key="index" class="img-list">
                    <img :src="item.fileUrl" alt="">
                </div>
            </div>

       </div>
         <div  v-if="!id" class="shouhou-submit" @click="handleSubmitRefund">提交申请</div>
    </div>

</template>
<script>
	import CONSTANT from "../../../wechat/static/constant/urlconstant";
	import common from "../../../wechat/static/common/common";
	import wsService from "../../../wechat/static/common/wechat-jsdk";
import card from '../common/Goods-card.vue'
import { XTextarea, Group} from 'vux'
import { setTimeout } from 'timers';
const testimg1 = require('../../images/test.png');
export default {
    data(){
        return{
            detail: {},
            isClick:false,
            id:'',
            params: {
	            orderCode: "",
	            imageList: [],
	            reason: "",
	            refundCode: "",
                refundType: "",
                logisticsCompany:'',
                shipmentNumber:''
            },
            selectlist: [{
                label: "退货",
                value: "WAIT_GET-EVALUATION",
                type: "REFUND_GOODS"
            },{
	            label: "退款",
	            value: "WAIT_SEND-PART_SEND",
                type: "ONLYREFUND"
            }],
            refundD:{},
            curIndex:0,
            selectArr:[],
            type:''
        }
    },
    components:{
    card,
    XTextarea,
     Group
  },
    mounted() {
        this.id = this.$route.query.id
        this.params.orderCode = this.$route.query.code
        this.type = this.$route.query.type
        this.getDetail()
        this.getDict()
        if(this.id){
            this.shouhouD()
        }
    },
   methods: {
       changeselect(index){
	    this.curIndex=index;
       },
       getDict(){
        let url = CONSTANT.LIST.LOADDICTIONARY
        common.get(url, 'exp', res => {
          if (res.code == 200) {
            this.selectArr = res.data.bussData
          }
        })
      },
       shouhouD() {
     		let url = CONSTANT.MY.refundDetail
            common.get(url, this.$route.query.id, (res) => {
            	if (res.code == 200) {
                    this.refundD = res.data.bussData
                    if(this.refundD.refundType == 'ONLYREFUND'){
                        this.curIndex = 1
                    }
                }
            })
       },
	   getDetail() {
     		let url = this.type?CONSTANT.ORDERTWO.ORDERDETAIL:CONSTANT.ORDER.ORDERDETAIL
            common.get(url, this.$route.query.code, (res) => {
            	if (res.code == 200) {
            		this.detail = res.data.bussData
                }
            })
        },
       handleMinus() {
       	    this.count = this.count + 1
	       this.params.refundPrice = this.detail.modelSalePrice * this.count
       },
       handleAdd() {
	       this.count = this.count - 1
	       this.params.refundPrice = this.detail.modelSalePrice * this.count
       },
	   handleBlurPrice(e) {
          let self = this
          if (e.target.value > this.detail.totalPrice) {
            this.$vux.alert.show({
              title: "提示",
              content: "不得超过最大可退商品金额"+self.detail.totalPrice
            })
            this.params.refundPrice = ''
          }
       },
     handleBlurFreightPrice(e) {
       let self = this
       if (e.target.value > this.freight) {
         this.$vux.alert.show({
           title: "提示",
           content: "不得超过最大可退运费金额"+this.freight
         })
         this.params.freightPrice = 0
       }
     },
     handleSubmitRefund() {
         if (this.isClick) return;
         this.isClick = true;
         this.params.refundType = this.selectlist[this.curIndex].type
         this.params.refundOrderType = this.type?this.type:'GOLD'
         this.$vux.loading.show({
           text: "申请中..."
         });
           let url = CONSTANT.REFUND.APPLY
           common.post(url, this.params, (res) => {
                if (res.code == 200) {
                    this.$vux.toast.hide();
                    setTimeout(()=>{
                      this.isClick = false;
                    //     setTimeout(()=>{
                    //   this.isClick = false;
                        this.$router.replace(`/aftSerOrder`)
                    // },500)
                    },500)
                }
           })
       },
	   handleDel(index) {
		   this.params.imageList.splice(index, 1)
       },
       leftBtn(){
        this.$router.back(-1)
        },
	   handleSelectPic(e) {
         console.log(e)
            if (this.params.imageList.length <5) {
                let url = CONSTANT.UPLOAD.UPLOAD
                common.formPost(url, {'suffix':e.target.files[0].name.split(".")[1]}, res => { 
                    let data = res.data.bussData;
                    common.uploadFile(data.uploadUrl, e.target.files[0], e.target.files[0].type, res => {
                        this.params.imageList.push({
				            fileKey: data.fileKey,
				            fileUrl: data.downloadUrl
			            })
                    });
                });
            }

       },
        onEvent (event) {
          console.log('on', event)
        }
  }
    
}
</script>
<style lang="less">
.shouhou{
    position: relative;
    padding-bottom: 80px;
    .img-wrap{
        overflow: hidden;
        background-color: #fff;
        padding: .3rem;
        .name{
            height: 30px;
            font-size: 14px;
        }
        .img-list{
            width: 1.44rem;
            height: 1.44rem;
            margin-bottom: .16rem;
            margin-right: .3rem;
            float: left;
            img{
                width: 1.44rem;
                height: 1.44rem;
            }
        }
    }
    .header-top{
    height: .8rem;
    line-height: .8rem;
    background:linear-gradient(-90deg,rgba(255,151,86,1),rgba(255,94,114,1));
    .arrow-left{
      position: absolute;
      left: .1rem;
      top: .1rem;
      height: .9rem;
      width: 1rem;
      z-index: 99;
      img{
        height: .5rem;
        width: .5rem;
      }
    }
  }
    .shouhou-bd{
        
        box-sizing: border-box;
        overflow: scroll-y;
        scroll-behavior: none;
        // margin-bottom:.2rem;
        .shouhou-card{
            background-color: #fff;
            padding: 0 .24rem;
            .card{
                // padding-left:.25rem;
                // padding-right:.25rem;
                box-sizing: border-box;
                border-bottom:.01rem solid rgba(238,238,238,.6);
                border-top:.01rem solid rgba(238,238,238,.6);
                .goods-item-content{
                box-sizing: border-box;
                height:2.3rem;
                padding-top:0rem;
                .good-desc{
                .good-desc-info{
                    font-size:.26rem;
                    font-family:PingFang-SC-Light; 
                    color:rgba(158,158,158,1);
                    line-height:.5rem;
                    margin-right:.2rem;
                    }
                }
                .good-price{
                    position: absolute;
                    bottom:0.1rem;
                    color:#FF7268;
                    .good-price-num{
                    font-size:.31rem;
                    font-family:PingFang-SC-Light;
                    line-height:.52rem;
                    }
                }
                .good-count{
                    position:absolute;
                    bottom:0.1rem;
                    right:0;
                    color:#666666;
                    font-size: .26rem;
                    font-family:PingFang-SC-Medium;
                }
                
                }
            }
            
        }
        .shouhou-select{
                display: flex;
                align-items: center;
                height: .96rem;
                padding-left: 15px;
                margin-top: .2rem;
                .shouhou-item{
                    width:1.3rem;
                    height:.48rem;
                    border:.01rem solid rgba(207,207,207,1);
                    border-radius:.24rem;
                    font-size:.24rem;
                    line-height: .48rem;
                    text-align: center;
                    font-family:PingFang-SC-Medium;
                    font-weight:500;
                    color:rgba(153,153,153,1);
                    margin-right: .3rem;
                }
                .shouhou-item-on{
                    .shouhou-item;
                    color:#FF7268;
                }

            }
        .backgood-number{
            margin-top: .44rem;
            box-sizing: border-box;
            font-size:.28rem;
            font-family:PingFang-SC-Medium;
            font-weight:500;
            color:rgba(51,51,51,1);
            line-height: .26rem;
            display: flex;
            align-items: center;
            flex-direction: row;
            padding-left: .3rem;
            .backgood-number-hint{
                margin-right: .41rem;
            }
            .change-number{
                display: flex;
                flex-direction: row;
                font-size:.32rem;
                font-family:PingFang-SC-Bold;
                font-weight:bold;
                color:rgba(51,51,51,1);
                width: 2.1rem;
                height: .6rem;
                background-color: #fff;
                justify-content: space-between;
                border: .01rem solid RGBA(207, 207, 207, 1);
                border-radius: 10%;
                .decrease-number{
                    width: .6rem;
                    display: flex;
                    align-items: center;
                    line-height: .6rem;
                    justify-content: center;
                    border-right:.01rem solid RGBA(207, 207, 207, 1); 

                }
                .increase-number{
                    .decrease-number;
                    border-left: .01rem solid RGBA(207, 207, 207, 1);
                    border-right: none;
                }
                .show-numer{
                    .decrease-number;
                    border: none;
                }
            }
           
        }
        .backmoney-amount{
            height: .88rem;
            box-sizing: border-box;
            font-size:.28rem;
            font-family:PingFang-SC-Medium;
            font-weight:500;
            color:rgba(51,51,51,1);
            line-height: .26rem;
            padding-left: .3rem;
            padding-top: .42rem;
      
        }
        .input-amount{
            display: flex;
            align-items: center;
            padding-left: .28rem;
            padding-right: .28rem;
            justify-content: space-between;
            height:.88rem;
            font-size:.36rem;
            font-family:PingFang-SC-Bold;
            font-weight:bold;
            color:rgba(51,51,51,1);
            background:rgba(255,255,255,1);
            select{
                height:.8rem;
                width: 7rem;
                border: 0px;
                background-color: #fff;
                &:focus{
                    outline: 0;
                }
            }
            img{
                width:.12rem;
                height:.22rem;
                float: right;
            }
            input{
                width: 100%;
            }
        }
        .input-amount2{
            min-height: 2rem!important;
            height: inherit!important;
            .reason-text{
                font-size: 14px;
            }
            .input-amount;
            padding-top: .29rem;
            appearance: none;
            align-items: flex-start;
            height: 2rem;
            margin-bottom: .3rem;
            textarea{
                width: 100%;
                padding: 0;
                border: none;
                height: 2rem;
            }
        }
        .uploadimg{
            // height:2.95rem;
            box-sizing: border-box;
            background:rgba(255,255,255,1);
            padding: .31rem 0 .24rem .3rem;
            display: flex;
            flex-direction: column;
            .uploadimg-hint{
                position: relative;
                font-size:.28rem;
                font-family:PingFang-SC-Medium;
                font-weight:500;
                color:rgba(51,51,51,1);
                line-height: .27rem;
                margin-bottom: .3rem;
            }
            .uploadimg-click{
                .upload-input {
                    position: relative;
                    width: 1.44rem;
                    height: 1.44rem;
                    overflow: hidden;
                    margin-bottom: .16rem;
                    margin-right: .3rem;
                    .hidden-input {
                        position: absolute;
                        z-index: 2;
                        left: 0;
                        width: 1.44rem;
                        height: 1.44rem;
                        top: 0;
                        opacity: 0;
                    }
                }
                img{
                    width: 1.44rem;
                    height: 1.44rem;
                    margin-bottom: .16rem;
                    margin-right: .3rem;
                }
                ul {
                    li {
                        position: relative;
                        .img-remove{
                            position: absolute;
                            top: -.16rem;
                            right: -.16rem;
                            width: .32rem ;
                            height: .32rem;
                        }
                    }
                }
                .uploaded-img{
                    display: inline-block;
                    position: relative;
                    .img-remove{
                        position: absolute;
                        top:0;
                        right: 0;
                        width: .32rem ;
                        height: .32rem;
                    }
                }
               
               
            }
            .uploadimg-limit{
                font-size:.22rem;
                line-height: .23rem;
                font-family:PingFang-SC-Medium;
                font-weight:500;
                color:rgba(136,136,136,1);
            }


            
        }
       
    }
     .shouhou-submit{
            position: fixed;
            bottom:0;
            left: 0;
            right: 0;
            margin-top:.41rem; 
            bottom: 0;
            height:.98rem;
            width: 7.5rem;
            background:linear-gradient(-90deg,rgba(255,151,86,1),rgba(255,94,114,1));
            font-size:.32rem;
            font-family:PingFang-SC-Medium;
            font-weight:500;
            color:rgba(255,255,255,1);
            line-height: .98rem;
            text-align: center;
        }
    
}
</style>
